<DOCTYPE html>
<html>
<head>
    <title>聚惠家</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php foreach ($this->config->item('style_css_paths') as $css): ?>
      <link rel="stylesheet" href=<?php echo $css ?> />
    <?php endforeach ?>
    <?php foreach ($this->config->item('style_js_paths') as $js): ?>
      <script type="text/javascript" src=<?php echo $js?> ></script>
    <?php endforeach ?>
    <script type="text/javascript" src=<?php echo base_url("/scripts/logic/uihelper.js") ;?>></script>
</head>
 
<body>
    <div data-role="page" id="history"> 
        <div data-role="header" data-tap-toggle="false" data-theme="a"  data-position="fixed">
            <!-- <h1>我的订单</h1> -->
            <div data-role="navbar">
                <ul>
                    <li><a href=<?php echo site_url('welcome/history') ;?> class="ui-btn-active ui-btn-icon-right ui-icon-shop">外卖历史</a></li>
                    <li><a href=<?php echo site_url('grouppurchase/history'); ?> class="ui-btn-icon-right ui-icon-grid">团购历史</a></li>
                </ul>
            </div><!-- /navbar -->
        </div>   
        <div role="main" class="ui-content">
            <ul data-role="listview" data-inset="true">
                <?php 
                    $last_date = "";
                    $echo_string = "";
                    $count = 0;
                    foreach ($history_bill as $item): 
                        $print_state = $item['print_state'];
                        $send_email =  $item['send_email'];
                        $print_info = "处理中";
                        if ($print_state == 1 or $send_email == 1)
                          $print_info = "已确认";
                        $now_date = date('Y-m-d', $item['time']);
                        $bill_json = json_decode($item['bill_json'],TRUE);
                        if ($now_date != $last_date){
                            if ($count > 0)
                            {
                                $echo_string = '<li data-role="divider">' . $last_date . '<span class="ui-li-count">' 
                                                . $count . '</span></li>' . $echo_string;
                                echo $echo_string;
                                $count = 0;
                            }
                            $bill_id = $item['bill_id'];
                            $echo_string = '<li><a href="' . site_url('welcome/historyBill?billid=') . $bill_id . '" data-rel="dialog" data-transition="pop">'
                                        . '<p>[' . $print_info . ']店铺名称:' . $bill_json['store_name'] . '</p>'
                                        . '<p class="ui-li-aside"><strong>' . date('H:i', $item['time']) . '</strong></p>'
                                        . '<p>总价格:' . $bill_json['total_price'] . '</p>'
                                        . '</a></li>';
                            $count++;
                        }
                        else
                        {
                            $count++;
                            $bill_id = $item['bill_id'];
                            $echo_string = $echo_string 
                                            . '<li><a href="' . site_url('welcome/historyBill?billid=') . $bill_id . '" data-rel="dialog" data-transition="pop">'
                                            //. '<p>店铺名称:' . $bill_json['store_name'] . '</p>'
                                            . '<p>[' . $print_info . ']店铺名称:' . $bill_json['store_name'] . '</p>'
                                            . '<p class="ui-li-aside"><strong>' . date('H:i', $item['time']) . '</strong></p>'
                                            . '<p>总价格:' . $bill_json['total_price'] . '</p>'
                                            . '</a></li>';
                        }
                        $last_date = $now_date;
                    endforeach;
                    if ($last_date != "")
                        $echo_string = '<li data-role="divider">' . $last_date . '<span class="ui-li-count">' 
                                    . $count . '</span></li>' . $echo_string;
                    else
                    { 
                        $echo_string = '
                            <div data-role="header" data-theme="a"  data-position="fixed">
                                <h1>我的订单</h1>
                            </div>    
                                  <div class="ui-bar ui-bar-a">
                                    <h3>查询失败</h3>
                                  </div>
                                  <div class="ui-body ui-body-a">
                                    <p>亲，您还没有下单，快去下单吧~</p>
                                  </div>
                                
                                <a href="' . site_url('welcome/shop') . '" class="ui-btn ui-btn-a">去下单</a>
                            <div data-role="footer" data-position="fixed">
                                <div data-role="navbar">
                                  <ul>
                                    <li><a href="' . site_url('welcome') . '" data-icon="home">主页</a></li>
                                    <li><a href="' . site_url('welcome/shop') . '" data-icon="shop" class="ui-btn-active ui-state-persist">店铺</a></li>
                                    <li><a href="' . site_url('welcome/index') . '" data-icon="check">历史订单</a></li>
                                    <li><a href="' . site_url('welcome/info')  . '" data-icon="info">个人信息</a></li>
                                  </ul>
                                </div>
                            </div>';
                    }
                    echo $echo_string;
                ?>
            </ul>
            <div data-role="controlgroup" style = "float: right" data-type="horizontal" class="ui-mini">
                <?php 
                    $page_num = $this->input->get("page_num", true);
                    $echo_string = "";
                    if ($page_num == "")
                        $page_num = 1;
                    if ($page_num == 1)
                    {
                        $echo_string = '<a class="ui-btn ui-btn-icon-right ui-icon-star">第1页</a>';
                    }
                    else
                    {
                        $last_page = $page_num-1;
                        $last_page = site_url('welcome/history?page_num=') . $last_page;
                        $echo_string = '<a href="' . $last_page 
                                        . '" class="ui-btn ui-btn-icon-right ui-icon-arrow-u">上一页</a>';
                        $echo_string = $echo_string . '<a class="ui-btn ui-btn-icon-right ui-icon-star">第'
                                        . $page_num . '页</a>';
                    }
                    if ($page_num*$per_page<$total_rows)
                    {
                        $next_page = $page_num+1;
                        $next_page = site_url('welcome/history?page_num=') . $next_page;
                        $echo_string = $echo_string . '<a href="' . $next_page
                                        . '" class="ui-btn ui-btn-icon-right ui-icon-arrow-d">下一页</a>';
                    }
                    echo $echo_string;
                ?>
            </div>
        </div>   
        <div data-role="footer" data-tap-toggle="false" data-position="fixed">
            <div data-role="navbar">
              <ul>
                <li><a href=<?php echo site_url('welcome');?> data-icon="home">主页</a></li>
                <li><a href=<?php echo site_url("welcome/shop") ;?> data-icon="shop" >店铺</a></li>
                <li><a href=<?php echo site_url('welcome/history');?>  data-icon="check" class="ui-btn-active ui-state-persist">历史订单</a></li>
                <li><a href=<?php echo site_url("welcome/info") ;?> data-icon="info">个人信息</a></li>
              </ul>
            </div>
        </div>
    </div> 


</body> 
</html>

